package com.zone.domain.strategy.model.valobj;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.logging.log4j.util.Strings;

import java.util.Map;
import java.util.Objects;

/**
 * @author: zongzi
 * @description: 规则树
 * @date: 2024/6/11
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RuleTreeVO {

    /** 规则树id */
    private String treeId;
    /** 规则树名称 */
    private String treeName;
    /** 规则树描述 */
    private String treeDesc;
    /** 规则树根节点key值 */
    private String treeRootNodeKey;

    /** 规则树节点集合 key: ruleKey, value: treeNode */
    private Map<String, RuleTreeNodeVO> treeNodeMap;

    // 获取根节点
    public RuleTreeNodeVO root() {
        return treeNodeMap.get(treeRootNodeKey);
    }

    /**
     * 根据节点规则编码获取树节点
     *
     * @param ruleKey 节点规则编码
     * @return 树节点
     */
    public RuleTreeNodeVO getNode(String ruleKey) {
        return treeNodeMap.get(ruleKey);
    }

    /**
     * 判断是否是一个空树
     *
     * @return true/false
     */
    public boolean isEmpty() {
        return Strings.isEmpty(treeRootNodeKey) || Objects.isNull(root());
    }
}
